package com.application.response;

import com.inboyu.admin.domain.OperationLogEntity;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 操作日志实体
 */
@Data
public class OperationLogResponse {

    private Long id;

    private String storeId;

    /**
     * 操作人
     */
    private String operator;

    /**
     * 操作行为
     */
    private String operation;

    /**
     * 操作时间
     */
    private LocalDateTime operationTime;

    /**
     * 操作结果详情
     */
    private String operationResult;

    /**
     * 业务类型
     */
    private String businessType;

    /**
     * 操作版本
     */
    private Integer version;

    public static List<OperationLogResponse> convertList(List<OperationLogEntity> operationLogs) {
    	if (!operationLogs.isEmpty()) {
            List<OperationLogResponse> operationLogResponses = new ArrayList<>(operationLogs.size());
            operationLogs.forEach(operationLog -> {
                OperationLogResponse operationLogResponse = convert(operationLog);
                operationLogResponses.add(operationLogResponse);
            });
            return operationLogResponses;
        }
    	return null;
    }

    public static OperationLogResponse convert(OperationLogEntity operationLog) {
        if (operationLog != null) {
            OperationLogResponse operationLogResponse = new OperationLogResponse();
            operationLogResponse.setId(operationLog.getId());
            operationLogResponse.setStoreId(operationLog.getStoreId().id());
            operationLogResponse.setOperator(operationLog.getOperator());
            operationLogResponse.setOperation(operationLog.getOperation());
            operationLogResponse.setOperationTime(operationLog.getOperationTime());
            operationLogResponse.setOperationResult(operationLog.getOperationResult());
            operationLogResponse.setBusinessType(operationLog.getBusinessType().code());
            operationLogResponse.setVersion(operationLog.getVersion());
            return operationLogResponse;
        }
    	return null;
    }
}
